<?php
/**
 * 
 * 
 * @version $Id: Nav.php 687 2013-03-05 10:52:45Z linsir123 $
 */
class Nav 
{
	/**
	 * 导航列表 - 头部
	 */
	static function header($params = null)
	{
		///
		return '<a id="btnFavorite" href="javascript:;">收藏本站</a>';
	}
	
	/**
	 * 导航列表 - 一级
	 */
	static function top($params = null)
	{
		$tmp = "";
		$navs = App::O('nav.top');
		foreach ($navs as $title => $nav) {
			$href = lpUrl::__($nav['r']);
			$hover = in_array($params['menu'], $nav['hover']) ? 'class="navhover"' : '';
			$tmp .= '<li '. $hover .'><a href="'. $href .'" title="'. $title .'">'. $title .'</a></li><li class="space"></li>';
		}
		
		///
		$navs = App::O('nav.channel');
		if (count($navs) > 0) {
			$i = 0;
			$format = lpUrl::__('goto/channel/%s');
			foreach ($navs as $key => $v) {
				if (++$$i == 1) 
					$tmp .= '<li class="has_sub"><a rel="nofollow" target="_blank" href="'. 
						sprintf($format, $key) .'">'. 
						$v[0] .'</a><ul class="sub clearfix">';
				else 
					$tmp .= '<li><a target="_blank" href="'. 
						sprintf($format, $key) .'">'. 
						$v[0] .'</a></li>';
			}
			$tmp .= '</ul></li>';
		}
		
		///
		return $tmp;
	}
	
	/**
	 * 导航列表 - 二级
	 */
	static function sub($params = null)
	{
		$mClasses = M::classes();
		
		///
		$cId = intval($params['cid']);
		
		///
		$class = $mClasses->get($cId);
		if ( ! empty($class)) {
			if ($class['pid'] == 0) 
				$classes = $mClasses->getSub($cId);
			else 
				$classes = $mClasses->getSub($class['pid']);
				
			///
			if (count($classes) > 0) {
				$i = 0;
				$tmp = null;
				foreach ($classes as $v) {
					if ($i++ >= 50) 
						break;
						
					///
					if ($cId == $v['id']) {
						$hover = 'class="submenu_cur"';
						$href = '#';
					} else {
						$hover = '';
						$href = Route::urlClass(array('cid'=>$v['id'], 'pinyin'=>$v['pinyin']));
					}
					$tmp .= '<a '. $hover .' href="'. $href .'" title="'. $v['title'] .'">'. $v['title'] .'</a>';
				}
				
				///
				return '<div id="Submenu" class="content clearfix">'. $tmp .'</div>';
			}
		}
		
		///
		return ;
	}
}
